/**
 * Forward declaration of guess API.
 * @param {number} num   your guess
 * @return 	            -1 if num is lower than the guess number
 *			             1 if num is higher than the guess number
 *                       otherwise return 0
 * var guess = function(num) {}
 */

var guess = function (num) {
  return num ? 0 : -1
}

/**
 * @param {number} n
 * @return {number}
 */
export var guessNumber = function (n) {
  let [left, right] = [1, n]
  while (left <= right) {
    let mid = left + ((right - left) >> 1)
    let res = guess(mid)
    if (res === 0) return mid
    if (res === -1) {
      right = mid - 1
    } else left = mid + 1
  }
  return -1
}
